package com.ssf.hsdtouch.view;

import com.ssf.hsdtouch.R;
import com.ssf.hsdtouch.R.layout;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;

public class PagerIndicator extends RadioGroup {

	public PagerIndicator(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.context = context;
	}

	public PagerIndicator(Context context) {
		super(context);
		this.context = context;
	}

	private int count = 0;
	private Context context;

	public void setCount(int count, int initCheckIndex) {
		if (count <= 0) {
			setVisibility(View.GONE);
			return;
		}
		this.count = count;
		removeAllViews();
		if (initCheckIndex > count - 1 || initCheckIndex < 0) {
			initCheckIndex = 0;
		}
		for (int i = 0; i < count; i++) {
			RadioButton btn = (RadioButton) LayoutInflater.from(context)
					.inflate(R.layout.layout_indicator, null);
			this.addView(btn);
		}
		this.check(((RadioButton) getChildAt(initCheckIndex)).getId());
		setOrientation(RadioGroup.HORIZONTAL);
		setVisibility(View.VISIBLE);
	}

	public void setCount(int count) {
		setCount(count, 0);
	}

	public void setCurrentItem(int index) {
		if (index <= count - 1 && index >= 0) {
			RadioButton btn = (RadioButton) this.getChildAt(index);
			this.check(btn.getId());
		}
	}
}
